<template>
	<view class="">
		<!-- 商品列表 -->
		<view class="newsItem" @click="gotodo(item.id),editClicknum(item.id,item.clickNum)" v-for="(item,index) in newsArr" :key="item.id">
			<image :src="item.imgUrl"></image>
			<view class="right">
				<view class="tit">
					{{item.title}}
				</view>
				<view class="info">
					<text>发表时间:{{item.addTime | formatDate}}</text>
					<text>浏览次数:{{item.clickNum}}</text>
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	export default{
		data(){
			return{
				abc:''
			}
		},
		props:["newsArr"],
		filters:{
			// 自定义时间处理过滤器 
			formatDate(date){
				//2023-01-05 15:05:19
				//2023-01-05 15:05
				let newdate = date.substring(0,date.lastIndexOf(":"))
				// console.log(newdate)
				return newdate;
			}
		},
		methods:{
			gotodo(id){
				// console.log("a")
				this.$emit("gotodo",id)
			},
			//get select query查询
			//del delect remove删除
			//edit set update修改
			//add insert添加
			async editClicknum(id,num){
				console.log("look",id)
				const res = await this.$myRequest({
					url:"/updateClickNum",
					data:{
						id:id,//当前新闻数据
						clickNum:++num//修改点击数量
					}
				})
				console.log(res)
				
			}
		}
	}
</script>

<style lang="scss">
	.newsItem{
		display:flex;
		padding:10rpx 20rpx;
		border-bottom: 1px solid $shop-color;
		image{
			min-width:200rpx;
			max-width: 200rpx;
			height: 150rpx;
		}
		.right{
			margin-left:15px;
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			.tit{
				font-size: 1rem;
			}
			.info{
				margin-top: 10px;
				font-size: 0.9rem;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				
			}
		}
	}
</style>